<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import { FormInstance } from '@arco-design/web-vue'
import Seller from '@/components/FormItem/Seller.vue'
const props = withDefaults(
  defineProps<{
    show: boolean
    id: number | string
    api: string
    /**是否是商户审核 商户多了个自动创建商户参数 */
    isSeller?: boolean
    /**是否是分销员审核 */
    isDistribution?: boolean
    /**传递接收的id 接口有的支持批量审核有的不支持 这里要做处理 */
    idKey?: string
  }>(),
  {
    idKey: 'ids',
  }
)
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  status: -1,
  remark: '',
  [props.idKey]: props.id,
  isCreate: 0,
  sellerId: [],
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query: any = Object.assign({}, detail)
      query.sellerId = query.sellerId.filter(Boolean).join(',')
      post(
        { url: props.api, data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          if (code == 200) {
            emit('update:show', false)
            emit('confirm')
          }
          done(code == 200)
        },
        () => done(false)
      )
    } else done(false)
  })
}
</script>
<template>
  <CModal v-model:visible="props.show" @before-ok="submit" :mask-closable="false" width="700px" title="审核" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="审核结果">
          <a-radio-group
            v-model="detail.status"
            :options="[
              { label: '通过', value: 1 },
              { label: '不通过', value: -1 },
            ]"
          />
        </a-form-item>
        <a-form-item label="是否自动创建商户" v-if="props.isSeller">
          <a-radio-group
            v-model="detail.isCreate"
            :options="[
              { label: '是', value: 1 },
              { label: '否', value: 0 },
            ]"
          />
        </a-form-item>
        <a-form-item label="归属商户" v-if="props.isDistribution && detail.status == 1" field="sellerId" :rules="[{ required: true, message: '请输入归属商户' }]" :validate-trigger="['change', 'blur']">
          <Seller v-model:val="detail.sellerId" multiple />
        </a-form-item>
        <a-form-item label="审核备注" field="remark" :rules="[{ required: true, message: '请输入审核备注' }]" :validate-trigger="['change', 'blur']">
          <a-textarea v-model="detail.remark" placeholder="请输入审核备注" />
        </a-form-item>
      </a-form>
    </div>
  </CModal>
</template>
<style lang="less" scoped></style>
